﻿using UnityEngine;
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

[Constructable]
public class ArmorBarrack : Building, IConstructable
{
	private double m_TurnCounter;				// for IConstructable

	#region IConstructable
	public double TurnCounter
	{
		get { return m_TurnCounter; }
		set { m_TurnCounter = value; }
	}
	#endregion

	public ArmorBarrack()
	{
		this.Name = GameEnums.Facilities.ArmorBarrack;
		this.DispName = Utility.SplitName(this.Name.ToString());
		
		this.MotherTech = new GameEnums.TechName[]{GameEnums.TechName.ArmorBarracks};
		Name = GameEnums.Facilities.ArmorBarrack;

		m_TurnCounter = 0;
	}
	
	public ArmorBarrack(bool getID) : this()
	{
		FacilityID = ++Galaxy.FacilitySerial;
		Core.Buildings.Add(FacilityID, this);
	}

	public ArmorBarrack(Planet pl)
	{
		Planet = pl;
	}

	public override void OnTurn()
	{
		base.OnTurn();
		m_TurnCounter++;

		if (m_TurnCounter == 10)
		{
			m_TurnCounter = 0;			// reset counter

			if (Planet.BaseDefense < Planet.CalPopulation() / 4)
				Planet.BaseDefense += 1;					// increase base defense every 10 turns, till basedefense = 1/4 population
		}

		Planet.Kingdom.Gold -= 2;
	}

	public override void OnTurn(Planet pl)
	{
		base.OnTurn(pl);

		Planet = pl;
		this.OnTurn();
	}

	public override void OnBuilt()
	{
		base.OnBuilt();

		Planet.BaseDefense += 2;
	}

	public override void OnBuilt(Planet pl)
	{
		base.OnBuilt(pl);

		Planet = pl;
		this.OnBuilt();
	}
}
